<?php
/**
 * 简历管理
 */

class EAdmin_Page_ResumeManage extends EAdmin_Page_Abstract
{
	private $resumeDb;
	private function loadDb()
	{
		$this->resumeDb = Db_Resume::instance();
	}
	public function validate(ME_Request $input, ME_Response $output)
	{
		$euserInfo = Libs_EUser::getLoginStatus($input,$output);
		$output->euid = 
			$input->euid =
			$euid = $euserInfo[0];

		if(empty($euid)){
			header("location:index.php?c=login");
		}

		$this->loadDb();
    		$sql = "select id, name from resume_state where eid='{$euid}' or eid='-1'";
        	$result = $this->resumeDb->getAll($sql);

        	$state_arr = array();
        	if($result){
                	foreach($result as $state){
                        	$state_arr[$state['id']] = $state['name'];
                	}
        	}

        	$output->state_arr = $state_arr;

		$config = ME_Config::get("ResumeState");
		$output->eduDegree = $eduDegree = $config['eduDegree'];

		$dataArr = Libs_Admin_Category::getCategoryList(array('module_type'=>1,'subclassid'=>0,'type'=>1,'pagesize'=>1000));
		$newDataArr = array();
		if($dataArr){
			foreach($dataArr as $data){
				$id = !empty($data['id']) ? $data['id'] : 0;
				if($id == 0){
					continue;
				}
				$newDataArr[$id] = $data['name'];
			}
		}
		$output->cityArr = $newDataArr;

		$stateinfo = Libs_EState::getEResumeState($euid);
		if(!empty($stateinfo)){
			$state_info = explode(",",$stateinfo);
		}else{
			$state_info = array();
		}
		$output->state_info = $state_info;

		$placeList = Libs_EUser::GetEPlace(array("eid"=>$euid));
		$output->placeList = $placeList['list'];

		//获取标签
		$sql = "select id, name from e_tags where firm_id={$euid} and is_del=0 order by sort_order desc";
		$tag_list = $this->resumeDb->getAll($sql);
		$output->tag_list = $tag_list;

		$commonOption = array(
                                'db'        => $this->resumeDb,
                                'fromSql'   => 'from e_job ',
                                'whereSql'  => "where firm_id = {$euid} ",
                                'onlyData'  => true,
                                'debug'     => false,
                                );
                $jobList = Libs_DBHelper::getList($commonOption);
		$job_list = array();
		if($jobList){
			foreach($jobList as $job){
				$job_list[$job['id']] = $job['name'];
			}
		}
		$output->job_list = $job_list;

		return true;
	}

	public function doDefault(ME_Request $input, ME_Response $output)
	{
		$fileExt = '';
		$page = $input->get("page");
		if(empty($page)){
			$page = 1;
		}

		$condition = '';

		$username = $input->get('username');
                if(!empty($username)){
                        $condition .= ' and trueName like "%'.$username.'%" ';
                        $fileExt .= '&username='.$username;
                }

                $sex = $input->get('sex');
                if(!empty($sex)){
                        $condition .= ' and sex='.$sex;
                        $fileExt .= '&sex='.$sex;
                }

		$degree = $input->get('degree');
                if(!empty($degree)){
                        $condition .= ' and degree='.$degree;
                        $fileExt .= '&degree='.$degree;
                }
		
		$schoolname = $input->get('schoolname');
                if(!empty($schoolname)){
                        $condition .= ' and schoolName like "%'.$schoolname.'%"';
                        $fileExt .= '&schoolname='.$schoolname;
                }

                $majorname = $input->get('majorname');
                if(!empty($majorname)){
                        $condition .= ' and majorName like "%'.$majorname.'%"';
                        $fileExt .= '&majorname='.$majorname;
                }

                $birthProv = $input->get('birthProv');
                if(!empty($birthProv))
                {
                        $condition .= ' and cur_province='.$birthProv;
                        $fileExt .= '&birthProv='.$birthProv;
                }

                $tag = $input->get('tag');
                if(!empty($tag)){
                        $condition .= ' and find_in_set("'.$tag.'",tag) ';
                        $fileExt .= '&tag='.$tag;
                }

                $is_primary = $input->get('is_primary');
		if(!empty($is_primary)){
			if($is_primary == "Y"){
               		        $condition .= ' and job_order=1 ';
                	}elseif($is_primary == "N"){
                        	$condition .= ' and job_order=0 ';
                	}
			$fileExt .= "&is_primary=".$is_primary;
		}
                
                $jobname = $input->get("jobname");
                if($jobname){
                        $condition .= ' and job_name='.$jobname;
                        $fileExt .= '&jobname='.$jobname;
                }       
                
                $state = $input->get("state");
                if($state){
                        $condition .= ' and state='.$state;
                        $fileExt .= '&state='.$state;
                }

		$resumeDb = Db_Resume::instance();

		$startnum = ($page-1) * 20;

		$sql = "select * from e_resume_search where eid={$input->euid} {$condition} limit {$startnum}, 20";
		$dataList = $resumeDb->getAll($sql);
		$output->dataList = $dataList;

		$count = $resumeDb->getOne("select count('X') from e_resume_search where eid={$input->euid} {$condition}");

		$pagestring = Libs_GlobalFunc::simplePage(array("page"=>$page, "pageSize"=>20, "total"=>$count, "baseUrl"=>"index.php?c=ResumeManage&page=", "fileExt"=>$fileExt));
		$output->pagestring = $pagestring;

		$output->setTemplate("ResumeManage");
	}

	public function doSearch(ME_Request $input, ME_Response $output)
	{
		$fileExt = "";
		$page = 1;

		$output->username = 
			$username = $input->post('username');
		if(!empty($username)){
			$condition .= ' and trueName like "%'.$username.'%" ';
                        $fileExt .= '&username='.$username;
		}

		$output->sex = 
			$sex = $input->post('sex');
		if(!empty($sex)){
			$condition .= ' and sex='.$sex;
                        $fileExt .= '&sex='.$sex;
		}

		$output->degree = 
			$degree = $input->post('degree');
		if(!empty($degree)){
			$condition .= ' and degree='.$degree;
                        $fileExt .= '&degree='.$degree;
		}

		$output->schoolname = 
			$schoolname = $input->post('schoolname');
		if(!empty($schoolname)){
			$condition .= ' and schoolName like "%'.$schoolname.'%"';
                        $fileExt .= '&schoolname='.$schoolname;
		}

		$output->majorname = 
			$majorname = $input->post('majorname');
		if(!empty($majorname)){
			$condition .= ' and majorName like "%'.$majorname.'%"';
                        $fileExt .= 'majorname='.$majorname;
		}

		$output->birthProv = 
			$birthProv = $input->post('birthProv');
		if(!empty($birthProv))
		{
			$condition .= ' and cur_province='.$birthProv;
                        $fileExt .= '&birthProv='.$birthProv;
		}
		$output->tag = 
			$tag = $input->post('tag');
		if(!empty($tag)){
			$condition .= ' and find_in_set("'.$tag.'",tag) ';
                        $fileExt .= '&tag='.$tag;
		}
		$output->is_primary = 
			$is_primary = $input->post('is_primary');
		if(!empty($is_primary)){
			$fileExt .= '&is_primary='.$is_primary;
		}
		if($is_primary == "Y"){
			$condition .= ' and job_order=1 ';
		}elseif($is_primary == "N"){
			$condition .= ' and job_order=0 ';
		}

		$output->jobname = 
			$jobname = $input->post("jobname");
		if($jobname){
			$condition .= ' and job_name='.$jobname;
                        $fileExt .= '&jobname='.$jobname;
		}

		$output->state =
			$state = $input->post("state");
		if($state){
			$condition .= ' and state='.$state;
                        $fileExt .= '&state='.$state;
		}

		$resumeDb = Db_Resume::instance();

		$startnum = ($page - 1) * 20;

		$sql = "select * from e_resume_search where eid={$input->euid} {$condition} limit {$startnum}, 20";
		$dataList = $resumeDb->getAll($sql);

		$output->dataList = $dataList;

		$count = $resumeDb->getOne("select count('X') from e_resume_search where eid={$input->euid} {$condition}");

                $pagestring = Libs_GlobalFunc::simplePage(array("page"=>$page, "pageSize"=>20, "total"=>$count, "baseUrl"=>"index.php?c=ResumeManage&page=", "fileExt"=>$fileExt));
                $output->pagestring = $pagestring;

		$output->setTemplate("ResumeManage");
	}

	//add
	public function doPlaceAdd(ME_Request $input, ME_Response $output)
	{
		//post
		if($input->post('add')){
			$addParam = '';
			$place_name = trim($input->post('name'));
			$eid = $input->euid;
			
			//add
			$insertId = Libs_EUser::AddEPlace(array('eid'=>$eid, 'name'=>$place_name));
			if($insertId){
				self::showMsg('添加成功','/index.php?c=ResumeManage');
			} else {
				self::showMsg('网络连接失败，请稍候再试','index.php?c=ResumeManage&a=PlaceAdd');
			}
		}

		$output->setTemplate("InterviewAdd");
	}

}
